<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        const str=1;

        /**
         * 解题思路：把整个字符串反转，然后做比较
         * @param {number} x
         * @return {boolean}
         */
        var isPalindrome1 = function(x) {
            const str=String(x);
            let reverse='';
            for(let i=str.length-1;i>-1;i--){
                reverse+=str[i];
            }
           
            return reverse==str? true:false;
        };

         /**
         * 解题思路：截取中间位，然后把左边和右边对比
         * 可以快一倍，因为少处理了一半
         * @param {number} x
         * @return {boolean}
         */
         var isPalindrome = function(x) {
             
            const str=String(x);
            const isEven=str.length%2 ===0
            let midIndex=Math.floor(str.length/2);
            let lefStr=str.substring(0,midIndex);
            let rightStr=''
            for(let i=str.length-1;isEven?i>=midIndex:i>midIndex;i--){
                rightStr+=str[i];
            }
            console.log(isEven,midIndex,lefStr,rightStr)
            return lefStr==rightStr;
        };


        /**
         * 解题思路：数字回文处理，截取中间位，然后把左边和右边对比
         * 可以快一倍，因为少处理了一半
         * @param {number} x
         * @return {boolean}
         */
         var isPalindrome = function(x) {
             
             const str=String(x);
             const isEven=str.length%2 ===0
             let midIndex=Math.floor(str.length/2);
             let lefStr=str.substring(0,midIndex);
             let rightStr=''
             for(let i=str.length-1;isEven?i>=midIndex:i>midIndex;i--){
                 rightStr+=str[i];
             }
             console.log(isEven,midIndex,lefStr,rightStr)
             return lefStr==rightStr;
         };

         let num=1534236469;
         function reverseNum(num){
            const isNagative=num<0;
    num=Math.abs(num);
    let revertedNum=0;
    const MAX_INT=Math.pow(2,31)-1
    const MIN_INT=-Math.pow(2,31)
    while (num>0){
        revertedNum=num%10+(revertedNum*10);
        //去掉个位数
        num=Math.floor(num/10);
    }
    const res =isNagative ? revertedNum*-1: revertedNum;

    return res>MAX_INT || res<MIN_INT  ? 0: res;
            }

            //console.log(reverseNum(num))
        //console.log(isPalindrome(str))

        /**
 * @param {number} x
 * @param {number} n
 * @return {number}
 */
 function pow(x, n) {
    if(n==0) return 1;
    const isNagative=n<0;
    n=Math.abs(n);
    for(let i=0;i<n;i++){
        if(isNagative){
            x=1/x;
        }else{
            i=1
            x*=x;
        }
        
    }
    return x;
};

console.log(pow(2,1))
    </script>
</body>
</html>